home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / prtcs155.zip / WFREQIT-.REX < prev    next >
OS/2 REXX Batch file  |  1994-01-14  |  9KB  |  288 lines

  1. /**/ 
  2. v="$VER: WFREQIT-CHECK Rexx  Check Incoming for Users  Williamson/Mollitt  54.00"
  3. /*
  4.     Based on FREQIT-IN.rx by Sean Mollitt
  5.  
  6.     This script should be run aftersession if requests have been sent out.
  7.  
  8.     If called during a cron event, it will scan the defined freq dir.
  9.  
  10.     What it does is check any file recd matches those requested by a user
  11.     (FREQIT.usr). If a match is found the file is moved to a special 
  12.     area and a message left for the user which he will receive next time
  13.     he uses FREQIT.
  14.     The  log  file  is updated, the file name is removed from the user file
  15.     and the user file is saved.  
  16. */ 
  17.  
  18. sv='v'||right(v,4)
  19. script="WfreqIt"
  20. call close('STDOUT')
  21. call open('STDOUT','RAW:0/10/640/130/ROOF 'script sv'/INACTIVE/AUTO/SCREEN'||GetClip('ASYNCSCREEN'),'w')
  22. call close('STDIN')
  23. call open('STDIN','*','R')
  24.    
  25.  
  26. /*-------------------------------------- User variables */
  27.  configpath = "CFG:freqit/freqit.cfg"
  28. /*----------------------------------------------------- */
  29.  
  30.     x=0;z=0;c=0;e=0;up=0;m=0;totk=0;totusers=0
  31.  
  32.     SAY "WfreqIt-Check "sv" Copyright 1993 Sean Mollitt & Robert Williamson"  
  33.  
  34.     IF ~show('L','rexxsupport.library') then
  35.         IF ~addlib('rexxsupport.library',0,-30,0) then 
  36.         do
  37.             say 'Error loading rexxsupport.library.'  
  38.             exit
  39.         end
  40.  
  41.  
  42. openconfigfile:
  43.  
  44.     IF ~OPEN('config',configpath,'R') then 
  45.     do
  46.         SAY "Error! Cannot find the config file (freqit.cfg) "    
  47.         signal shutdown
  48.     END
  49.  
  50. readconfigline:
  51.     cfgln = TRANSLATE(READLN('config'),' ','09'x) /* strips tabs out of config */
  52.     IF LEFT(STRIP(cfgln),1) ~= ';' & COMPRESS(cfgln) ~= "" then 
  53.     DO
  54.         x=x+1
  55.         IF STRIP(WORD(cfgln,1))='BBSLIST' then 
  56.         DO
  57.             z=z+1
  58.             bbsname.z  = STRIP(TRANSLATE(READLN('config'),' ','09'x))
  59.             offset= POS(';',bbsname.z)-1
  60.             IF offset > 0 then bbsname.z = STRIP(LEFT(bbsname.z,offset)) 
  61.             filelist.z = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  62.             node.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  63.             time.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  64.             type.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  65.             access.z   = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  66.             signal readconfigline
  67.         END 
  68.         cfg.x = STRIP(STRIP(WORD(cfgln,2)),'B','"')
  69.     END
  70.  
  71. IF ~EOF('config') then signal readconfigline
  72.  
  73. filedir = cfg.1
  74. indir   = cfg.2
  75. maxreq  = cfg.3
  76. maxk    = cfg.4
  77. maxover = cfg.5
  78. callout = cfg.6
  79. outnode = cfg.7
  80. txtfile = cfg.8
  81. hlpfile = cfg.9
  82. usrfile = cfg.10
  83. logfile = cfg.11
  84. msgtxt  = cfg.12
  85. msgarea = cfg.13
  86. netarea = cgf.14
  87. maxdays = cfg.15
  88. outbound = cfg.16
  89. pollcmd = cfg.17
  90. hostaddr = cfg.18
  91. userfs=cfg.19
  92. loggroup=cfg.20
  93.  
  94.     parse arg scandir .
  95.     if arg()=0 then scandir=indir
  96.         else scandir=addslash(scandir)
  97.  
  98. openuserfile:
  99.     IF ~OPEN('user',usrfile,'R') then 
  100.     do
  101.         SAY "Error! Cannot find the user file (freqit.usr) "  
  102.         signal shutdown
  103.     END
  104.  
  105.     say "Loading user config"
  106. readuserfile:    
  107.     usrline = UPPER(READLN('user'))
  108.     IF EOF('user') then signal freqit
  109.     m=m+1 ; i=0 ; files.m=0
  110.     name.m= usrline
  111.     totusers = m
  112.     DO FOREVER
  113.         i=i+1
  114.         usrline = READLN('user')
  115.         IF WORD(usrline,1)= "#" then BREAK
  116.         PARSE VAR usrline file.m.i filek.m.i filed.m.i filea.m.i filestat.m.i fileto.m.i filedes.m.i
  117.         files.m = i
  118.     END
  119.  
  120.     IF ~EOF('user') then signal readuserfile
  121.  
  122. freqit:
  123.  
  124.     CALL CLOSE('user')
  125.     if m=0 then 
  126.     DO
  127.         call putlog("FREQIT.usr is empty. No files waiting")
  128.         signal shutdown
  129.     END
  130.  
  131.     call putlog('Scanning 'scandir)
  132.     inlist = UPPER(SHOWDIR(scandir,'F'))
  133.     if inlist="" then
  134.     do
  135.         say scandir' is empty'
  136.         signal shutdown
  137.     end
  138.  
  139.     i=0
  140.     DO FOREVER
  141.         i=i+1
  142.         PARSE VAR inlist infile.i inlist
  143.         IF infile.i == "" then BREAK
  144.     END
  145.     i=i-1
  146.  
  147.     DO x = 1 to i
  148.         DO a = 1 to totusers
  149.             DO b = 1 to files.a
  150.                 IF UPPER(file.a.b) = UPPER(infile.x) & filestat.a.b = 'waiting' then 
  151.                 DO
  152.                     c=c+1
  153.                     usermsg=msgarea||TRANSLATE(name.a,'_',' ')
  154.  
  155.                     if ~exists(usermsg) then address COMMAND "Copy" msgtxt usermsg
  156.                         
  157.                     call putlog(file.a.b||" received for "||name.a||". "||TRANSLATE(fileto.a.b,' ','_')||" notified.") 
  158.                     say file.a.b||" received for "||name.a||". "||TRANSLATE(fileto.a.b,' ','_')||" notified." 
  159.  
  160.  
  161.                     openmode='a'
  162.                     IF ~OPEN('msgadd',usermsg,'A') then 
  163.                     do
  164.                         If ~open('msgadd',usermsg,'W') then 
  165.                         do
  166.                             SAY "Error opening "usermsg   
  167.                             signal shutdown
  168.                         end
  169.                         openmode='w'
  170.                     END
  171.  
  172.                     filedes.a.b = STRIP(COMPRESS(filedes.a.b,'"'),'B')
  173.             
  174.                     if indir ~= scandir then
  175.                     do
  176.                         address COMMAND 'Copy' scandir||file.a.b indir
  177.                         if RC=0 then
  178.                         do
  179.                             call delete(scandir||file.a.b)
  180.                             say scandir||file.a.b 'moved to 'indir
  181.                         end
  182.                     end
  183.                     address COMMAND 'FileNote' indir||file.a.b '"'filedes.a.b'"'
  184.                     say indir||file.a.b filedes.a.b
  185.  
  186.                     if openmode='w' then
  187.                     do
  188.                         CALL WRITELN('msgadd'," WFREQIT "sv" by Sean Mollitt & Robert Williamson ⌐ 1993")
  189.                         CALL WRITELN('msgadd'," ------------------------------------------------------------")
  190.                     end
  191.                     CALL WRITELN('msgadd',"")
  192.                     CALL WRITELN('msgadd'," File name  : "||file.a.b||"  ("||filek.a.b||")     Freq'ed from: "||filea.a.b)
  193.                     CALL WRITELN('msgadd'," Description: "||filedes.a.b)
  194.                     CALL CLOSE('msgadd')
  195.  
  196.                     smsg='LOG:RFSacct/'translate(name.a,"_"," ")'.m'
  197.                     if exists(smsg) then call open('um',smsg,'A')
  198.                         else  call open('um',smsg,'W')
  199.                     call writeln('um',' WFREQIT file reception report')
  200.                     CALL WRITELN('um'," File name  : "||file.a.b||"  ("||filek.a.b||")     Freq'ed from: "||filea.a.b)
  201.                     CALL WRITELN('um'," Description: "||filedes.a.b)
  202.                     call close('um')
  203.  
  204.                     logentry.c = LEFT(infile.x,20)||"  "||LEFT(name.a,20)||"  "||DATE('E')||"  "||filea.a.b||"  "fileto.a.b
  205.                     filestat.a.b = DATE('E')
  206.                 END
  207.             END 
  208.         END
  209.     END
  210.  
  211.     if c=0 then 
  212.     DO
  213.         call putlog("No incoming files match any waiting user files")
  214.         signal shutdown
  215.     END
  216.  
  217. logit:
  218.     IF ~OPEN('log',logfile,'A') then 
  219.     do
  220.         IF ~OPEN('log',logfile,'W') then 
  221.         do
  222.             SAY "Error! Cannot find log file (freqit.log) "   
  223.             signal shutdown
  224.         END
  225.         CALL WRITELN('log','FREQIT 'sv' LOG FILE')
  226.         CALL WRITELN('log','File requested        User                  Date in    From Node     Destin. ')
  227.         CALL WRITELN('log','-------------------------------------------------------------------------------')
  228.     END
  229.     i=0
  230.     DO i = 1 to c
  231.         CALL WRITELN('log',logentry.i)
  232.     END
  233.     CALL CLOSE('log')
  234.  
  235. openuserfilewrite:
  236.  
  237.     IF ~OPEN('user',usrfile,'W') then 
  238.     do
  239.         SAY "Error! Cannot find the userfile" 
  240.         signal shutdown
  241.     END
  242.  
  243. writeuserfile:
  244.     i=0
  245.     DO o = 1 to totusers
  246.         DO q = 1 to files.o
  247.             i=i+1
  248.             IF file.o.q = "IN" then i=i-1 
  249.         END
  250.         IF i ~= 0 THEN 
  251.         DO
  252.             CALL WRITELN('user',name.o)
  253.             do p = 1 to files.o
  254.                 filedat= LEFT(file.o.p,20)||"  "||RIGHT(filek.o.p,7)||"  "||filed.o.p||"  "||filea.o.p||"  "||LEFT(filestat.o.p,8)||" "||fileto.o.p||" "||filedes.o.p
  255.                 CALL WRITELN('user',filedat)
  256.             END
  257.             CALL WRITELN('user','#')
  258.         END
  259.     END
  260.  
  261.     CALL CLOSE('user')
  262.  
  263.     SAY "User file updated and saved" 
  264.  
  265. shutdown:
  266. EXIT
  267.  
  268.  
  269. /* get filename */
  270. get_fn:
  271.     if LastPos('/', arg(1)) ~= 0 then return SubStr(arg(1), LastPos('/', arg(1)) + 1)
  272.         else if LastPos(':', arg(1)) ~= 0 then return SubStr(arg(1), LastPos(':', arg(1)) + 1)
  273.             else return arg(1)
  274.  
  275. addslash:
  276.     curr = arg(1)
  277.     select
  278.         when right(curr, 1) = ":" then nop
  279.         when right(curr, 1) = "/" then nop
  280.             otherwise curr = curr"/"
  281.     end
  282. return(curr)
  283.  
  284.  putlog:
  285.     say arg(1)
  286.     Address "LOGPROC" "Putlog "loggroup time() arg(1)
  287.  return
  288.